package com.ruoyi.system.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.system.domain.DevelopException;
import com.ruoyi.system.mapper.DdReportMapper;
import com.ruoyi.system.service.IDdReportService;
import com.ruoyi.system.vo.DevelopExceptionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 钉钉报表 服务层实现
 * 
 * @author ruoyi
 */
@Service
@DataSource(value = DataSourceType.DDBB)
public class DdReportServiceImpl implements IDdReportService
{
    @Autowired
    private DdReportMapper ddbbMapper;



    /**
     * 查询参数配置列表
     * 
     * @param config 参数配置信息
     * @return 参数配置集合
     */
//    @Override
//    public List<SysConfig> selectConfigList(SysConfig config)
//    {
//        return configMapper.selectConfigList(config);
//    }

    @DS("ddbb")
    @Override
    public List<DevelopException> selectDevelopExceptions(DevelopExceptionVO exceptionVO) throws Exception {
        checkTime(exceptionVO);
        return ddbbMapper.selectDevelopExceptions(exceptionVO);
    }

    private void checkTime(DevelopExceptionVO exceptionVO) throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = sdf.parse(exceptionVO.getDateStart());
        Date endDate = sdf.parse(exceptionVO.getDateEnd());
        long time1 = endDate.getTime();
        long time2 = startDate.getTime();
        long time = time1 - time2;
        System.out.println(time + "=" + time1 + "-" + time2);
        if(time > 31536000000L || time < 0){
            throw new Exception("查询时间期间不允许超过12个月。");
        }
    }
}
